package test

import (
	"entdemo/ent"

	"log"

	_ "github.com/go-sql-driver/mysql"
)

var client *ent.Client

func init() {
	var err error
	client, err = ent.Open("mysql", "dev:root@tcp(127.0.0.1:3306)/kratos_test?parseTime=True", ent.Debug())
	if err != nil {
		log.Fatalf("failed opening connection to mysql: %v", err)
	}
	//client.Debug()
	// 开启sql日志
	// Add a global hook that runs on all types and all operations.
	/*
		client.Use(func(next ent.Mutator) ent.Mutator {
			return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) {
				start := time.Now()
				fmt.Println("hook注册执行:", start)
				defer func() {
					log.Printf("Op=%s\tType=%s\tTime=%s\tConcreteType=%T\n", m.Op(), m.Type(), time.Since(start), m)
				}()
				return next.Mutate(ctx, m)
			})
		})*/
}
